/**
 * @author: HZWei
 * @date: 2024/7/15
 * @desc:
 */

const fs = require("fs");
const path = require("path");
// require('json5/lib/register')


// 将绝对路径转成相对路径
// from 和 to都写绝对路径
const rpath =  path.relative("src/main/ets/generated/","src/pages/home-page")
console.log(rpath)

console.log(__dirname)

class PluginConfig {
    scanDir = './src/main/ets/'
    generatedDir = './src/main/ets/generated/'
    indexDir = __dirname
    moduleJsonPath = './src/main/ets/module.json5'
}
const config = new PluginConfig()

function checkIfModuleRouterMapConfig() {
    // 检查 module.json5文件是否配置路由表文件
    const module =  require(config.moduleJsonPath)
    if (module?.module?.routerMap) return
    module.module.routerMap = "$profile:route_map"
    fs.writeFileSync(config.moduleJsonPath, JSON.stringify(module, null, 2), {encoding: "utf8"})

}
// checkIfModuleRouterMapConfig()

function logger(...args){
    console.log('logger: ',...args)
}

logger(config,55)

let p2 = 'D:\\learn\\harmony\\learn-demos\\samples\\ZRouter\\harA\\src\\main\\ets\\_generated\\'
let p1 =  'D:\\learn\\harmony\\learn-demos\\samples\\ZRouter\\harA\\src\\main\\ets\\components\\MainPage'
let p = 'D:\\learn\\harmony\\learn-demos\\samples\\ZRouter\\harA\\src\\main\\ets\\_generated\\builderRegister.ets'

let pp = path.relative(p2,p1).replace(/\\/g, '/')
console.log(pp)

